package org.lulee007;

import static org.apache.commons.lang3.StringUtils.defaultString;

import java.io.File;
import java.io.FileFilter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.jsonschema2pojo.AllFileFilter;
import org.jsonschema2pojo.AnnotationStyle;
import org.jsonschema2pojo.Annotator;
import org.jsonschema2pojo.GenerationConfig;
import org.jsonschema2pojo.NoopAnnotator;
import org.jsonschema2pojo.SourceType;
import org.jsonschema2pojo.rules.RuleFactory;


public class HmJsonGeneratorConfig implements GenerationConfig {

    private boolean showHelp = false;

    private String targetPackage;

    private File targetDirectory;

    private List<URL> sourcePaths;

    private boolean generateBuilderMethods = false;

    private boolean generateConstructors = false;

    private boolean constructorsRequiredPropertiesOnly = false;

    private boolean usePrimitives = false;

    private String propertyWordDelimiters = "- _";

    private boolean useLongIntegers = false;

    private boolean useFloatNumbers = false;

    private boolean omitHashcodeAndEquals = false;

    private boolean omitToString = false;

    private AnnotationStyle annotationStyle = AnnotationStyle.GSON;

    private Class<? extends Annotator> customAnnotator = NoopAnnotator.class;


    private Class<? extends RuleFactory> customRuleFactory = RuleFactory.class;

    private boolean includeJsr303Annotations = false;

    private SourceType sourceType = SourceType.JSON;

    private boolean removeOldOutput = false;

    private String outputEncoding = "UTF-8";

    private boolean useJodaDates = false;

    private boolean useJodaLocalDates = false;
    private boolean useJodaLocalTimes = false;

    private boolean useCommonsLang3 = false;

    private boolean parcelable = false;

    private boolean nullCollections = false;

    private String classNamePrefix = "";

    private String classNameSuffix = "";

    private static final int EXIT_OKAY = 0;
    private static final int EXIT_ERROR = 1;

    /**
     * Parses command line arguments and populates this command line instance.
     * <p/>
     * If the command line arguments include the "help" argument, or if the
     * arguments have incorrect values or order, then usage information is
     * printed to {@link System#out} and the program terminates.
     *
     * @param args the command line arguments
     * @return an instance of the parsed arguments object
     */
    public HmJsonGeneratorConfig(String source, String target) {
        this.targetDirectory = new File(target);
        this.sourcePaths = new ArrayList<URL>();
        try {
            this.sourcePaths.add(new URL(source));
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }


    public Iterator<URL> getSource() {
        return sourcePaths.iterator();
    }


    public File getTargetDirectory() {
        return targetDirectory;
    }


    public String getTargetPackage() {
        return targetPackage;
    }


    public boolean isGenerateBuilders() {
        return generateBuilderMethods;
    }


    public boolean isUsePrimitives() {
        return usePrimitives;
    }


    public char[] getPropertyWordDelimiters() {
        return defaultString(propertyWordDelimiters).toCharArray();
    }


    public boolean isUseLongIntegers() {
        return useLongIntegers;
    }


    public boolean isUseDoubleNumbers() {
        return !useFloatNumbers;
    }


    public boolean isIncludeHashcodeAndEquals() {
        return !omitHashcodeAndEquals;
    }


    public boolean isIncludeToString() {
        return !omitToString;
    }


    public AnnotationStyle getAnnotationStyle() {
        return annotationStyle;
    }


    public Class<? extends Annotator> getCustomAnnotator() {
        return customAnnotator;
    }


    public Class<? extends RuleFactory> getCustomRuleFactory() {
        return customRuleFactory;
    }


    public boolean isIncludeJsr303Annotations() {
        return includeJsr303Annotations;
    }


    public SourceType getSourceType() {
        return sourceType;
    }


    public boolean isRemoveOldOutput() {
        return removeOldOutput;
    }


    public String getOutputEncoding() {
        return outputEncoding;
    }


    public boolean isUseJodaDates() {
        return useJodaDates;
    }


    public boolean isUseJodaLocalDates() {
        return useJodaLocalDates;
    }


    public boolean isUseJodaLocalTimes() {
        return useJodaLocalTimes;
    }


    public boolean isUseCommonsLang3() {
        return useCommonsLang3;
    }


    public boolean isParcelable() {
        return parcelable;
    }

    protected void exit(int status) {
        System.exit(status);
    }


    public FileFilter getFileFilter() {
        return new AllFileFilter();
    }


    public boolean isInitializeCollections() {
        return !nullCollections;
    }


    public String getClassNamePrefix() {
        return classNamePrefix;
    }


    public String getClassNameSuffix() {
        return classNameSuffix;
    }

    /**
     * Gets the 'includeConstructors' configuration option
     *
     * @return Whether to generate constructors or not.
     */

    public boolean isIncludeConstructors() {
        return generateConstructors;
    }

    /**
     * Gets the 'constructorsRequiredPropertiesOnly' configuration option
     *
     * @return Whether generated constructors should have parameters for all properties, or only required ones.
     */

    public boolean isConstructorsRequiredPropertiesOnly() {
        return constructorsRequiredPropertiesOnly;
    }


}
